<?php
/**
 * Created by PhpStorm.
 * User: luzy
 * Date: 2018/5/29
 * Time: 下午12:22
 */

class Salesmanartvisitor extends Base_Controller
{
    public function __construct()
    {
        $this->_page_size = 20;
        $this->_form_type = 'salesman_art_visitor';
        $this->_list_where = array('s.sls'=>'');
        $this->_action_list = array();
        $this->_controller = 'admin/salesman/salesmanartvisitor/';//admin/user/
        parent::__construct();
    }

    public function showList($sls = '',$page = 1)
    {
        $this->_external_id=$sls;
        $this->_list_where['s.sls']=$sls;
        $limit = $this->_page_size;
        $offset = ($page-1) * $limit;
        $pdata = $this->getPagination($this->_controller.'showList/'.$this->_external_id.'/');

        $res = $this->getList($offset,$limit);

        //有返回按钮
        $backbtn = $this->load->view('admin/form/backbtn',array('controller'=>site_url('admin/salesman/salesmanmanage/')),true);

        $data = array('headers'=>$res['headers'],'list'=>$res['list'],'pagination'=>$pdata['pagination'],'backbtn'=>$backbtn);
        $content = $this->load->view('admin/form/list',$data,true);

        echo $this->getAdminView($content);
    }

    public function getList($offset = 0,$limit = 0)
    {
        $header = array("头像","访客","阅读文章");
        $this->load->model('kdtsalesman_model');
        $list = $this->kdtsalesman_model->getSalesmanartvisitorListData($this->_controller,$this->_list_where,$limit,$offset);
        $res = array('headers'=>$header,'list'=>$list);
        return $res;
    }

    public function getPagination($uri = '')
    {
        $this->db->select('s.uid')->from('mod_slsarticle_stat as s');
        if (!empty($this->_list_where)) $this->db->where($this->_list_where);
        $this->db->group_by("s.uid");
        $totalres = $this->db->get()->result_array();
        $total = count($totalres);

        $this->load->library('pagination');
        $config['base_url'] = site_url($uri);
        $config['total_rows'] = $total;
        $config['per_page'] = $this->_page_size;
        $config['suffix'] = '?'.$_SERVER['QUERY_STRING'];
        $config['first_url'] = $config['base_url'].'1?'.$_SERVER['QUERY_STRING'];
        $config['cur_tag_open'] = '<div class="cur-page">';
        $config['cur_tag_close'] = '</div>';
        $config['use_page_numbers'] = TRUE;
        $config['num_tag_open'] = '<div class="pageitem">';
        $config['num_tag_close'] = '</div>';
        $config['prev_link'] = '上一页';
        $config['prev_tag_open'] = '<div class="pre-page">';
        $config['prev_tag_close'] = '</div>';
        $config['next_link'] = '下一页';
        $config['next_tag_open'] = '<div class="next-page">';
        $config['next_tag_close'] = '</div>';
        $config['last_link'] = '最后一页';
        $config['last_tag_open'] = '<div class="last-page">';
        $config['last_tag_close'] = '</div>';
        $config['first_link'] = '第一页';
        $config['first_tag_open'] = '<div class="first-page">';
        $config['first_tag_close'] = '</div>';
        $config['full_tag_open'] = '<div class="page-total-results">共'.$total.'条，每页'.$this->_page_size.'条</div>';

        $this->pagination->initialize($config);

        return array('total'=>$total,'pagination'=>$this->pagination->create_links());
    }

    public function update($id = 0,$sls = ''){}
    public function afterupdate($pkey,$pkeyval){}

    public function create($sls = ''){}

    public function aftercreate($pkeyval)
    {
        /*$pkey为主键，$pkeyval为主键值*/
    }

    public function delete($id = 0,$externalid = 0){}

    public function afterdelete($pkey,$pkeyval){}
}